Socket
Socket
Sign inDemoInstall

flux

Package Overview
Dependencies
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flux

An application architecture based on a unidirectional data flow


Version published
Weekly downloads
593K
decreased by-19.74%
Maintainers
3
Weekly downloads
 
Created

What is flux?

Flux is an application architecture for building client-side web applications. It complements React's composable view components by utilizing a unidirectional data flow. This makes it easier to reason about your application and helps you avoid complex state management issues.

What are flux's main functionalities?

Dispatcher

The Dispatcher is a central hub that manages all data flow in a Flux application. It receives actions and dispatches them to the appropriate stores.

const { Dispatcher } = require('flux');
const dispatcher = new Dispatcher();
dispatcher.register((payload) => {
  console.log('Received payload:', payload);
});
dispatcher.dispatch({ type: 'ACTION_TYPE', data: 'sample data' });

Store

Stores contain the application state and logic. They register with the Dispatcher to receive actions and update their state accordingly. They also emit change events to notify views of state changes.

const { Dispatcher } = require('flux');
const EventEmitter = require('events').EventEmitter;
const dispatcher = new Dispatcher();
class Store extends EventEmitter {
  constructor() {
    super();
    this.data = null;
    dispatcher.register(this.handleAction.bind(this));
  }
  handleAction(action) {
    if (action.type === 'ACTION_TYPE') {
      this.data = action.data;
      this.emit('change');
    }
  }
  getData() {
    return this.data;
  }
}
const store = new Store();
store.on('change', () => {
  console.log('Store changed:', store.getData());
});
dispatcher.dispatch({ type: 'ACTION_TYPE', data: 'sample data' });

Action

Actions are simple objects that contain new data and a type property. They are dispatched to the Dispatcher, which then forwards them to the appropriate stores.

const { Dispatcher } = require('flux');
const dispatcher = new Dispatcher();
const action = {
  type: 'ACTION_TYPE',
  data: 'sample data'
};
dispatcher.dispatch(action);

Other packages similar to flux

Keywords

FAQs

Package last updated on 17 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc